def main():
    n=int(input())
    list_people=list(range(1,n+1))
    del_position=0
    k=1
    while len(list_people)>1:
        if k%7==0 or '7'in str(k):
            list_people.pop(del_position)
            del_position%=len(list_people)if len(list_people)>0 else 0
        else:
            del_position+=1
            del_position%=len(list_people)
        k+=1
    print(list_people[0])
main()